/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package biblio.bl;

import biblio.modelo.Libro;
import biblio.dao.LibroDaoLocal;
import biblio.enumeracion.EstadoTransaccion;
import biblio.modelo.Categoria;
import biblio.modelo.Categoriadelibro;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;

/**
 *
 * @book Grnmnd
 */
@Stateless
public class LibroBl implements LibroBlLocal {
    @EJB
    private LibroDaoLocal libroDao;

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")

    @Override
        public EstadoTransaccion register(Libro book, List<Categoriadelibro> categoriadelibro) {
            book.setCategoriadelibroList(categoriadelibro);
        if (libroDao.FindDuplicity(book)) {
            return EstadoTransaccion.INCOMPLETO;
        } else {
            libroDao.create(book);
            return EstadoTransaccion.COMPLETO;
        }

    }

    @Override
    public EstadoTransaccion modify(Libro book) {
        if (book.getId() == null || libroDao.find(book.getId()) == null) {
            return EstadoTransaccion.INCOMPLETO;
        } else {
            libroDao.edit(book);
            return EstadoTransaccion.COMPLETO;
        }
    }

    @Override
    public EstadoTransaccion delete(Libro book) {
        if (book.getId() == null || libroDao.find(book.getId()) == null) {
            return EstadoTransaccion.INCOMPLETO;
        } else {
            libroDao.remove(book);
            return EstadoTransaccion.COMPLETO;
        }
    }
    
    
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")

    @Override
    public List<Libro> getListAll() {
        return libroDao.findAll();
    }

}
